using System;
using System.Runtime.Serialization;

namespace Metro.Admin.BusinessEntities
{
    [DataContract]
	public class Transaction 
    {
        private DateTime date;
        private string id = string.Empty;
        private string idOrderPost = string.Empty;
        private string idOrderGet = string.Empty;
        private decimal tax=0;
        private decimal baseTax = 0;
        private decimal taxTransaction = 0;
        private decimal amount=0;
        private decimal basePrice=0;
        private decimal commission = 0;
        private decimal total=0;
        private int type = 0;
        private string idPair = string.Empty;
        private Order originalOrder;
        private OrderState state = OrderState.Active;   
        private bool markForDelete = false;
        private int deleteExpiration = 0;

		public Transaction()
        {}

        [DataMember]
        public DateTime Date
        {
            get { return this.date; }
            set { this.date = value; }
        }

        [DataMember]
        public String Id
        { 
          get { return this.id; }
          set { this.id = value; }
        }

        [DataMember]
        public String IdOrderPost
        {
            get { return this.idOrderPost; }
            set { this.idOrderPost = value; }
        }

        [DataMember]
        public String IdOrderGet
        {
            get { return this.idOrderGet; }
            set { this.idOrderGet = value; }
        }
       
        [DataMember]
        public Decimal Tax
        {
            get { return this.tax; }
            set { this.tax = value; }
        }

        [DataMember]
        public Decimal BaseTax
        {
            get { return this.baseTax; }
            set { this.baseTax = value; }
        }

        [DataMember]
        public Decimal TaxTransaction
        {
            get { return this.taxTransaction; }
            set { this.taxTransaction = value; }
        }

        [DataMember]
        public Decimal Amount
        {
            get { return this.amount; }
            set { this.amount = value; }
        }

        [DataMember]
        public Decimal BasePrice
        {
            get { return this.basePrice; }
            set { this.basePrice = value; }
        }

        [DataMember]
        public Decimal Commission
        {
            get { return this.commission; }
            set { this.commission = value; }
        }

        [DataMember]
        public Decimal Total
        {
            get { return this.total; }
            set { this.total = value; }
        }

        [DataMember]
        public int Type
        {
            get { return this.type; }
            set { this.type = value; }
        }

        [DataMember]
        public Order OriginalOrder
        {
            get { return this.originalOrder; }
            set { this.originalOrder = value; }
        }

        [DataMember]
        public String IdPair
        {
            get { return this.idPair; }
            set { this.idPair = value; }
        }

        [DataMember]
        public string TransactionStateString
        {
            get { return Enum.GetName(typeof(OrderState), this.state); }
            set { }
        }

        [DataMember]
        public OrderState TransactionState
        {
            get { return this.state; }
            set { this.state = value; }
        }

        [DataMember]
        public String UserId
        {
            get { return this.originalOrder.UserId; }
            set {  }
        }

        [DataMember]
        public String BusinessTypeString
        {
            get { return this.originalOrder.BusinessTypeString ; }
            set { }
        }

        [DataMember]
        public Boolean MarkForDelete
        {
            get { return this.markForDelete; }
            set { this.markForDelete =value; }
        }

        [DataMember]
        public int DeleteExpiration
        {
            get { return this.deleteExpiration; }
            set { this.deleteExpiration = value; }
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (this.GetType() != obj.GetType()) return false;

            Transaction transaction = (Transaction)obj;

            return this.id.Equals(transaction.id);
        }


        public override int GetHashCode()
        {
            return base.GetHashCode();
        } 


	}

    [DataContract(Name = "TransaccionOperation")]
    public enum TransaccionOperation
    {
        [EnumMember]
        New,
        [EnumMember]
        AskDelete,
        [EnumMember]
        Delete,
        [EnumMember]
        Reject
    }

    public class TransaccionalPair
    {
        public TransaccionalPair() { }
        public TransaccionalPair(Transaction tA, Transaction tB)
        {
            this.transactionA = tA;
            this.transactionB = tB;
        }

        private Transaction transactionA;
        private Transaction transactionB;

        public Transaction TransactionA
        {
            get
            {
                return this.transactionA;
            }

            set
            {
                this.transactionA = value;
            }
        }

        public Transaction TransactionB
        {
            get
            {
                return this.transactionB;
            }

            set
            {
                this.transactionB = value;
            }
        }

        public void Add(Transaction t)
        {
            if (this.TransactionA == null)
            {
                this.TransactionA = t;
                return;
            }

            if (this.TransactionB == null)
            {
                this.TransactionB = t;
                return;
            }
        }
    }

    public class PreTransactionSummary
    {
        public PreTransactionSummary() { }

        private decimal avgBuy = 0;
        private decimal avgSell = 0;
        private decimal totalBuy = 0;
        private decimal totalSell = 0;

        public Decimal AvgBuy
        {
            get {return this.avgBuy;}
            set {this.avgBuy = value;}
        }

        public Decimal AvgSell
        {
            get { return this.avgSell; }
            set { this.avgSell = value; }
        }

        public Decimal TotalBuy
        {
            get { return this.totalBuy; }
            set { this.totalBuy = value; }
        }

        public Decimal TotalSell
        {
            get { return this.totalSell; }
            set { this.totalSell = value; }
        }

    
    }

    public class UserStats
    {
        public UserStats() { }

        private decimal avgBuy = 0;
        private decimal avgSell = 0;
        private decimal profit = 0;
        private decimal position = 0;

        public Decimal AvgBuy
        {
            get { return this.avgBuy; }
            set { this.avgBuy = value; }
        }

        public Decimal AvgSell
        {
            get { return this.avgSell; }
            set { this.avgSell = value; }
        }

        public Decimal Profit
        {
            get { return this.profit; }
            set { this.profit = value; }
        }

        public Decimal Position
        {
            get { return this.position; }
            set { this.position = value; }
        }
    }
}